package com.yy.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * ClassName: PageHelper
 * Package: com.yy.common.util
 * Description:
 *
 * @Author yy
 * @Create 2023-12-27 22:46
 * @Version 1.0
 */
public class PageHelper {
    public static <T, J> Page<J> copyMap(IPage<T> source, Function<? super T, ? extends J> mapper) {
        Page<J> newPage = new Page<>();
        newPage.setSize(source.getSize());
        newPage.setTotal(source.getTotal());
        newPage.setPages(source.getPages());
        newPage.setRecords(source.getRecords().stream().map(mapper).collect(Collectors.toList()));
        newPage.setCurrent(source.getCurrent());
        return newPage;
    }
}
